package cn.cuilan.controller;

import cn.cuilan.service.PositionAreaService;
import cn.cuilan.service.PositionCityService;
import cn.cuilan.service.PositionCountryService;
import cn.cuilan.service.PositionProvinceService;
import cn.cuilan.utils.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 地理位置Controller
 *
 * @author zhang.yue
 */
@RestController
@RequestMapping("/admin/position")
public class AdminPositionController {

    private static final Logger logger = LoggerFactory.getLogger(AdminPositionController.class);

    private PositionCountryService positionCountryService;
    private PositionProvinceService positionProvinceService;
    private PositionAreaService positionAreaService;
    private PositionCityService positionCityService;

    @Autowired
    public AdminPositionController(PositionCountryService positionCountryService,
                                   PositionProvinceService positionProvinceService,
                                   PositionAreaService positionAreaService,
                                   PositionCityService positionCityService) {
        this.positionCountryService = positionCountryService;
        this.positionProvinceService = positionProvinceService;
        this.positionAreaService = positionAreaService;
        this.positionCityService = positionCityService;
    }

    @RequestMapping(value = "/country", method = RequestMethod.GET)
    public Results getPositionCountry() {
        return Results.success().data(positionCountryService.findAllPositionCountry());
    }

    @RequestMapping(value = "/province", method = RequestMethod.GET)
    public Results getPositionProvince(@RequestParam(value = "cid") int countryId) {
        return Results.success().data(positionProvinceService.findProvinceByCountryId(countryId));
    }

    @RequestMapping(value = "/area", method = RequestMethod.GET)
    public Results getPositionArea(@RequestParam(value = "pid") int provinceId) {
        return Results.success().data(positionAreaService.findAreaByProvinceId(provinceId));
    }

    @RequestMapping(value = "/city", method = RequestMethod.GET)
    public Results getPositionCity(@RequestParam(value = "aid") int areaId) {
        return Results.success().data(positionCityService.findCityByAreaId(areaId));
    }

}
